{extend name="../public/header" /}
{block name="body"}
<body>
{include file="../public/common" /}
<div class="layui-form">
	<table class="layui-table" lay-size="sm">
		<thead>
			<tr>
				<th>序号</th>
				<th>文件名</th>
				<th>文件大小</th>
				<th>备份时间</th>
				<th width="220">管理选项</th>
			</tr>
		</thead>
		<tbody>
		{if(count($list)<1)}
			<tr>
				<td colspan="5" align="center">暂无相关数据</td>
			</tr>
			{else /}
			{foreach name="list" item="vo"}
			<tr>
				<td>{$key+1}</td>
				<td>{$vo.file}</td>
				<td>{$vo.size}</td>
				<td>{$vo.time}</td>
				<td>
					<a class='layui-btn layui-btn-xs' href="{:url('backup/download',array('file'=>$vo['file']))}">
						<i class="layui-icon">&#xe601;</i>下载
					</a>
					<a class="layui-btn layui-btn-xs ajax-sure" data-url='{:url("backup/restore")}' data-field="file" data-value="{$vo.file}">还原</a>
					<a class="layui-btn layui-btn-xs layui-btn-danger ajax-del" data-url='{:url("backup/del")}' data-field='file' data-value='{$vo.file}'>
						<i class="layui-icon">&#xe640;</i>删除
					</a>
				</td>
			</tr>
			{/foreach}
		{/if}
		</tbody>
		<tr>
			<td colspan="5" align="center">
				<a class="layui-btn layui-btn-sm ajax-bf">备份数据库</a>
			</td>
		</tr>
	</table>
</div>
<div class="text-right">
    <div class="layui-box">
        注：1、本操作是对数据库 {$dbname} 的备份，存储于站点根目录 mysql 文件夹下。
    </div>
</div>
</body>
{/block}
{block name="script"}
<script>
layui.use(['jquery','form','layajax','layer'], function(){
	var $ = layui.jquery
		,form = layui.form
		,layer = layui.layer
		,layajax = layui.layajax;
	
	$('.ajax-bf').on('click',function(){
		var index2 = layer.load(2, {time: 60*1000});

		var id=1;
		$.post('{:url("backup/back")}', {'id': id}, function (res) {
			layer.close(index2);

			console.log(res);
			res = JSON.parse(res);

			if(res.code == 1) {
				layer.msg(res.msg,{icon:1,time:2000}, function(index){
					location.reload();
				});
			} else {
				layer.msg(res.msg);
			}
		});
		
	});
	
	form.render();
});
</script>
{/block}
